/******************************************************************************/
package jamie.org.sil.www.usxUtils;

import java.io.*;


/******************************************************************************/
/**
   A class which holds a book assembly element where we are taking the list
   of elements from the available files in the input folder.

   This class is very rudimentary, and we could probably get away with having
   a special class for this purpose, rather then implementing the BookElement
   interface.  However I have a feeling we may want to do rather better than
   this at some point.
*/

public class BookElementFromFileList implements BookElement
{
  /****************************************************************************/
  /****************************************************************************/
  /**                                                                        **/
  /**                                 Public                                 **/
  /**                                                                        **/
  /****************************************************************************/
  /****************************************************************************/

  /****************************************************************************/
  /**
     Constructor.

     At the time of writing, the only rationale for taking all files from the
     input folder is when we are processing USFM and turning it into USFMX
     or USX.  In these cases, we don't actually care what the filename is,
     because we work out what book it relates to from its context.

     One consequence of this, however, is that it doesn't make sense to ask
     the present class things about the relevant output file name, etc,
     because this is determined from the 

     @param inputFileName File name (not path name) of input file.
  */
  
  public BookElementFromFileList (String inputFileName)
  {
    super();
    m_InputFileName = inputFileName;
  }

    
  /****************************************************************************/
  /**
     Gets the string to be used as the anchor.  For scripture entries, this
     is left blank, because it has to be generated during processing.
    
     For peripheral files it's more complicated, because I have an ideal, but
     I also have to cater for the fact that we have legacy data which
     doesn't conform to that ideal, and I get the impression we may well
     not be able to move to the new form.
    
     So, if fileNameReadFromConfig is non-null (which means we're catering
     for legacy data), we remove the file extension and any wildcards, and
     use that.  Otherwise (my preferred option) we use the vernacular string
     selector.
    
     @return Anchor.
   */

  @Override public String getAnchorName ()
  {
    return "";
  }


  /****************************************************************************/
  /* Returns the file name (not the path name) for the cross-references file.
     The cross-references file name is organised as follows :-.
    
     * "" => Cross-references go to the scripture file.
    
     * Null => No cross-references.
    
     * Anything else is the actual file name.
    
     Note that if references are being combined to a single file, the return
     value is the name of that file.  Otherwise it's the name of a
     per-scripture-file file (which is the name of the scripture file with
     "-xref" added to it).

     @param chapterNumber Needed where output is per chapter.

     @return File name of cross-references file.
   */

  @Override public String getCrossReferencesFileName (int chapterNumber)
  {
    return "";
  }



  /****************************************************************************/
  /** Returns the full pathname of the output file.

      @param chapterNo Needed where output is per chapter.

      @return Full path name of cross-references file.
  */

  @Override public String getCrossReferencesPathName (int chapterNo)
  {
    return "";
  }


  /******************************************************************************/
  /**
     Returns the file name (not path name) for the endnotes file (always an
     empty string).

     @return Footnotes file name.
    */

  @Override public String getEndnotesFileName (int chapterNo)
  {
    return "";
  }


  /******************************************************************************/
  /**
     Returns the full pathname of the endnotes file (always an empty string).

     @return Notes path name.
  */

  @Override public String getEndnotesPathName (int chapterNo)
  {
    return "";
  }


  /******************************************************************************/
  /**
     Returns the file name (not path name) for the footnotes file (always an
     empty string).

     @return Footnotes file name.
    */

  @Override public String getFootnotesFileName (int chapterNo)
  {
    return "";
  }


  /******************************************************************************/
  /**
     Returns the full pathname of the footnotes file (always an empty string).

     @return Notes path name.
  */

  @Override public String getFootnotesPathName (int chapterNo)
  {
    return "";
  }


  /****************************************************************************/
  /**
     Returns the group to which this file belongs (relevant to scripture files
     only -- eg Gospels, Pentateuch).

     @return Group.
  */
  
  @Override public String getGroup ()
  {
    return "";
  }

  
  /****************************************************************************/
  /**
     Returns the name of any image file associated with the given peripheral
     file name.

     @return Image file name.
  */
  
  @Override public String getImageFileName ()
  {
    return "";
  }


  /****************************************************************************/
  /**
     Checks if the input file exists.

     @return True if input file exists.
  */
  
  @Override public boolean getInputFileExists ()
  { 
    try
    { 
      return (new File(getInputPathName())).exists();
    }
    catch (Exception e)
    { 
      return false; 
    }
  }
    
 
  /****************************************************************************/
  /**
     Returns the name (not the path) of the input file.

     The input file name is deduced from the name of the scripture book on
     scripture elements.  On peripherals, it is the value supplied by the
     user, unless no value has been supplied, in which case we use a
     wildcarded name based on the vernacular string selector.  Otherwise
     there is no input file.

     @return Name of input file.
  */

  @Override public String getInputFileName ()
  {
    return m_InputFileName;
  }


  /****************************************************************************/
  /**
     Returns the full path name for the input file.

     @return Path name for input file.
   */

  @Override public String getInputPathName ()
  {
    String s1 = Config.instance().getInputFolderPath();
    String s2 = getInputFileName();
    if (null == s1) s1 = "";
    if (null == s2) s2 = "";
    return s1 + s2;
  }


  /****************************************************************************/
  /**
     Returns the file name (not path name) of the file containing introductory material.

     The introductory-material file name is organised as follows :-.
    
     * "" => Intro goes to the scripture file.
    
     * Null => No introductory material.
    
     * Anything else is the actual file name.
    
     Note that if the material being combined to a single file, the return
     value is the name of that file.  Otherwise it's the name of a
     per-scripture-file file (which is the name of the scripture file with
     "-intro" added to it).

     @return Introduction file name.
  */

  @Override public String getIntroFileName (int chapterNumber)
  {
    return "";
  }


  /****************************************************************************/
  /**
     Returns the full pathname of the output file.

     @return Introduction file path name.
  */

  @Override public String getIntroPathName (int chapterNo)
  {
    return "";
  }


  /****************************************************************************/
  /**
     Checks if the output file exists.

     @param chapterNo Chapter number (of interest where we are generating
                      output per chapter).

     @return True if output file exists.
  */
  
  @Override public boolean getOutputFileExists (int chapterNo) 
  {
    return false;
  }
    
    
  /************************************************************************/
  /**
     Returns the file name (not the path name) of the output file.
     
     If we're dealing with scripture, then the output file name is based
     on the name of the book, unless we're sending all output to a single
     file, in which case it's the name defined for that file.
     
     Otherwise, if we're dealing with a peripheral file, I return an
     empty string, and it's down to the caller to use the same name
     as the input file they have actually selected.
     
     Otherwise (for notes or TOC), it's the specific name defined in the
     config.
     
     Otherwise it's empty (although I don't think we should ever hit this).

     @return File name of output file.
  */
    
  @Override public String getOutputFileName (int chapterNumber)
  {
    String s = getInputFileName();
    return s.substring(0, s.length() - Config.instance().getInputFileExtension().length()) +
           Config.instance().getOutputFileExtension();
  }


  /****************************************************************************/
  /*
    Returns the full pathname of the output file.

    @return Path name of output file.
  */

  @Override public String getOutputPathName (int chapterNo)
  {
    return Config.instance().getOutputFolderPath() + getOutputFileName(chapterNo);
  }


  /****************************************************************************/
  /**
     Returns the type of the file (scripture, peripheral, etc).

     @return File type.
  */
  
  @Override public String getType ()
  {
    return "";

  }


  /****************************************************************************/
  /**
     Returns the the UBS abbreviation for the file.  Returns an empty string
     on non-scripture items.

     @return UBS abbreviation.
  */

  @Override public String getUbsAbbreviation ()
  {
    return "";
  }


  /****************************************************************************/
  /**
     Returns the vernacular string for the file.
     
     The vernacular string is the string to be displayed for this item in
     TOCs, etc.  On scripture files, it's the name of the book.  On peripheral
     files we obtain it by looking up the relevant vernacular string, unless
     there <i>is</i> no such string, in which case we just use the English.

     @return Vernacular string.
  */
    
  @Override public String getVernacularString ()
  {
    return "";
  }


  /******************************************************************************/
  /**
     Returns the vernacular string selector for the file.

     @return Vernacular string selector.
  */
    
  @Override public String getVernacularStringSelector ()
  {
    return "";
  }

  
  /****************************************************************************/
  /**
     Returns an indication of whether this file should feature in the TOC.

     @return True if file should appear in the TOC.
  */
  
  @Override public boolean inToc ()
  {
    return false;
  }





  /****************************************************************************/
  /****************************************************************************/
  /**                                                                        **/
  /**                                Private                                 **/
  /**                                                                        **/
  /****************************************************************************/
  /****************************************************************************/

  /****************************************************************************/
  private String m_InputFileName = "";
}
